<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>华为全球新品订购 - HUAWEI Global Store</title>
    <style>
        .disabled-btn {
            background-color: #ccc !important;
            color: #666 !important;
            cursor: not-allowed !important;
            pointer-events: none; /* 禁止点击 */
        }

        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
            background: #f8fafc;
            color: #1f2937;
            overflow-x: hidden;
        }

        .container {
            max-width: 1200px;
            margin: 0 auto;
            padding: 0 20px;
        }

        /* Header */
        .header {
            background: linear-gradient(135deg, #1e40af 0%, #3b82f6 100%);
            color: white;
            padding: 15px 0;
            box-shadow: 0 4px 20px rgba(0,0,0,0.1);
            position: sticky;
            top: 0;
            z-index: 1000;
        }

        .header-content {
            display: flex;
            justify-content: space-between;
            align-items: center;
        }

        .logo {
            font-size: 28px;
            font-weight: bold;
            display: flex;
            align-items: center;
            gap: 10px;
            cursor: pointer;
        }

        .logo::before {
            content: "🌐";
            font-size: 24px;
        }

        .nav {
            display: flex;
            gap: 30px;
            align-items: center;
        }

        .nav a {
            color: white;
            text-decoration: none;
            font-weight: 500;
            transition: all 0.3s ease;
            padding: 10px 15px;
            border-radius: 8px;
        }

        .nav a:hover {
            background: rgba(255,255,255,0.2);
            transform: translateY(-2px);
        }

        .user-actions {
            display: flex;
            gap: 15px;
            align-items: center;
        }

        .cart-icon {
            position: relative;
            padding: 10px;
            background: rgba(255,255,255,0.2);
            border-radius: 50%;
            cursor: pointer;
            transition: all 0.3s ease;
        }

        .cart-icon:hover {
            background: rgba(255,255,255,0.3);
            transform: scale(1.1);
        }

        .cart-count {
            position: absolute;
            top: -5px;
            right: -5px;
            background: #ef4444;
            color: white;
            border-radius: 50%;
            width: 20px;
            height: 20px;
            font-size: 12px;
            display: flex;
            align-items: center;
            justify-content: center;
        }

        .btn {
            padding: 15px 30px;
            border: none;
            border-radius: 10px;
            font-size: 16px;
            font-weight: 600;
            cursor: pointer;
            transition: all 0.3s ease;
            text-decoration: none;
            display: inline-block;
            text-align: center;
        }

        .btn-primary {
            background: linear-gradient(135deg, #3b82f6, #1d4ed8);
            color: white;
        }

        .btn-primary:hover {
            background: linear-gradient(135deg, #1d4ed8, #1e40af);
            transform: translateY(-2px);
            box-shadow: 0 8px 25px rgba(59, 130, 246, 0.3);
        }

        .btn-outline {
            background: transparent;
            border: 2px solid #3b82f6;
            color: #3b82f6;
        }

        .btn-outline:hover {
            background: #3b82f6;
            color: white;
        }

        .btn-full {
            width: 100%;
        }

        /* Hero Section */
        .hero {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            padding: 80px 0;
            text-align: center;
            position: relative;
            overflow: hidden;
        }

        .hero::before {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><defs><pattern id="grid" width="10" height="10" patternUnits="userSpaceOnUse"><path d="M 10 0 L 0 0 0 10" fill="none" stroke="rgba(255,255,255,0.1)" stroke-width="0.5"/></pattern></defs><rect width="100" height="100" fill="url(%23grid)"/></svg>');
            opacity: 0.3;
        }

        .hero-content {
            position: relative;
            z-index: 1;
        }

        .hero h1 {
            font-size: 48px;
            margin-bottom: 20px;
            font-weight: 700;
            text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
        }

        .hero p {
            font-size: 20px;
            margin-bottom: 40px;
            opacity: 0.9;
        }

        .countdown {
            background: rgba(255,255,255,0.2);
            padding: 20px;
            border-radius: 15px;
            display: inline-block;
            backdrop-filter: blur(10px);
            margin-bottom: 30px;
        }

        .countdown-title {
            font-size: 18px;
            margin-bottom: 15px;
            opacity: 0.9;
        }

        .countdown-timer {
            display: flex;
            gap: 20px;
            justify-content: center;
        }

        .time-unit {
            text-align: center;
        }

        .time-number {
            font-size: 32px;
            font-weight: bold;
            display: block;
            line-height: 1;
            transition: all 0.3s ease;
        }

        .time-label {
            font-size: 14px;
            opacity: 0.8;
            margin-top: 5px;
        }

        /* 倒计时结束状态 */
        .countdown-ended {
            background: linear-gradient(135deg, #10b981, #059669);
            animation: celebration 2s ease-in-out infinite alternate;
        }

        .countdown-ended .countdown-title {
            font-size: 24px;
            font-weight: bold;
        }

        @keyframes celebration {
            0% { transform: scale(1); }
            100% { transform: scale(1.05); }
        }

        /* Product Showcase */
        .product-showcase {
            padding: 80px 0;
            background: white;
        }

        .section-title {
            text-align: center;
            font-size: 36px;
            font-weight: bold;
            margin-bottom: 50px;
            color: #1f2937;
        }

        .product-grid {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
            gap: 40px;
        }

        .product-card {
            background: white;
            border-radius: 20px;
            box-shadow: 0 10px 40px rgba(0,0,0,0.1);
            overflow: hidden;
            transition: all 0.3s ease;
            cursor: pointer;
        }

        .product-card:hover {
            transform: translateY(-10px);
            box-shadow: 0 20px 60px rgba(0,0,0,0.15);
        }

        .product-image {
            height: 250px;
            background: linear-gradient(135deg, #f3f4f6, #e5e7eb);
            position: relative;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 48px;
        }

        .product-info {
            padding: 30px;
        }

        .product-title {
            font-size: 24px;
            font-weight: bold;
            margin-bottom: 10px;
        }

        .product-price {
            font-size: 28px;
            font-weight: bold;
            color: #3b82f6;
            margin-bottom: 15px;
        }

        .product-description {
            color: #6b7280;
            margin-bottom: 20px;
            line-height: 1.6;
        }

        .product-features {
            margin-bottom: 25px;
        }

        .feature-tag {
            display: inline-block;
            background: #f1f5f9;
            color: #475569;
            padding: 5px 12px;
            border-radius: 15px;
            font-size: 12px;
            margin: 3px;
        }

        .stock-status {
            display: flex;
            align-items: center;
            gap: 10px;
            margin: 15px 0;
        }

        .stock-indicator {
            width: 12px;
            height: 12px;
            border-radius: 50%;
            background: #10b981;
        }

        .stock-indicator.low {
            background: #f59e0b;
        }

        .stock-indicator.out {
            background: #ef4444;
        }

        /* Global Features */
        .global-features {
            padding: 80px 0;
            background: #f8fafc;
        }

        .features-grid {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
            gap: 30px;
        }

        .feature-item {
            text-align: center;
            padding: 30px 20px;
            background: white;
            border-radius: 15px;
            box-shadow: 0 5px 20px rgba(0,0,0,0.05);
        }

        .feature-icon {
            font-size: 48px;
            margin-bottom: 20px;
        }

        .feature-title {
            font-size: 20px;
            font-weight: bold;
            margin-bottom: 10px;
        }

        .feature-description {
            color: #6b7280;
            line-height: 1.6;
        }

        /* Newsletter */
        .newsletter {
            padding: 80px 0;
            background: linear-gradient(135deg, #1f2937, #374151);
            color: white;
            text-align: center;
        }

        .newsletter-form {
            max-width: 500px;
            margin: 30px auto 0;
            display: flex;
            gap: 15px;
        }

        .newsletter-input {
            flex: 1;
            padding: 15px 20px;
            border: none;
            border-radius: 10px;
            font-size: 16px;
        }

        .newsletter-input:focus {
            outline: none;
            box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.3);
        }

        /* Footer */
        .footer {
            background: #1f2937;
            color: white;
            padding: 60px 0 30px;
        }

        .footer-content {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
            gap: 40px;
            margin-bottom: 40px;
        }

        .footer-section h3 {
            margin-bottom: 20px;
            font-size: 18px;
        }

        .footer-section ul {
            list-style: none;
        }

        .footer-section li {
            margin-bottom: 10px;
        }

        .footer-section a {
            color: #9ca3af;
            text-decoration: none;
            transition: color 0.3s ease;
        }

        .footer-section a:hover {
            color: white;
        }

        .footer-bottom {
            text-align: center;
            padding-top: 30px;
            border-top: 1px solid #374151;
            color: #9ca3af;
        }

        /* Responsive Design */
        @media (max-width: 768px) {
            .nav {
                display: none;
            }
            
            .hero h1 {
                font-size: 32px;
            }
            
            .countdown-timer {
                flex-wrap: wrap;
                gap: 10px;
            }
            
            .product-grid {
                grid-template-columns: 1fr;
            }

            .newsletter-form {
                flex-direction: column;
            }
        }

        /* Animations */
        .fade-in {
            animation: fadeIn 0.6s ease-in-out;
        }

        @keyframes fadeIn {
            from { opacity: 0; transform: translateY(20px); }
            to { opacity: 1; transform: translateY(0); }
        }

        .pulse {
            animation: pulse 2s infinite;
        }

        @keyframes pulse {
            0%, 100% { opacity: 1; }
            50% { opacity: 0.7; }
        }

        /* 数字跳动动画 */
        .time-number.updating {
            animation: numberUpdate 0.3s ease-in-out;
        }

        @keyframes numberUpdate {
            0% { transform: translateY(0); }
            50% { transform: translateY(-5px); color: #fbbf24; }
            100% { transform: translateY(0); }
        }

        /* Modal */
        .modal {
            display: none;
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: rgba(0,0,0,0.7);
            z-index: 2000;
            backdrop-filter: blur(5px);
        }

        .modal.active {
            display: flex;
            align-items: center;
            justify-content: center;
        }

        .modal-content {
            background: white;
            padding: 40px;
            border-radius: 20px;
            text-align: center;
            max-width: 500px;
            width: 90%;
            box-shadow: 0 20px 60px rgba(0,0,0,0.3);
            animation: modalSlideIn 0.3s ease;
        }

        @keyframes modalSlideIn {
            from {
                transform: translateY(-50px);
                opacity: 0;
            }
            to {
                transform: translateY(0);
                opacity: 1;
            }
        }

        .queue-info {
            margin-bottom: 30px;
        }

        .queue-position {
            font-size: 48px;
            font-weight: bold;
            color: #3b82f6;
            margin-bottom: 10px;
        }

        .queue-progress {
            width: 100%;
            height: 10px;
            background: #f3f4f6;
            border-radius: 5px;
            overflow: hidden;
            margin: 20px 0;
        }

        .queue-progress-bar {
            height: 100%;
            background: linear-gradient(90deg, #3b82f6, #1d4ed8);
            transition: width 1s ease;
        }

        .queue-entertainment {
            background: #f8fafc;
            padding: 20px;
            border-radius: 10px;
            margin-top: 20px;
        }

        .loading-spinner {
            display: inline-block;
            width: 30px;
            height: 30px;
            border: 3px solid #f3f4f6;
            border-top: 3px solid #3b82f6;
            border-radius: 50%;
            animation: spin 1s linear infinite;
        }

        @keyframes spin {
            0% { transform: rotate(0deg); }
            100% { transform: rotate(360deg); }
        }
        
    </style>
</head>
<body>
    <!-- Header -->
    <header class="header">
        <div class="container">
            <div class="header-content">
                <div class="logo" onclick="window.location.href='index.html'">HUAWEI Global Store</div>
                
                <nav class="nav">
                    <a href="index.html">首页</a>
                    <a href="product-list.html">新品</a>
                    <a href="support.html">支持</a>
                    <a href="about.html">关于</a>
                </nav>
                
                <div class="user-actions">
                    <select style="padding: 8px; border-radius: 5px; border: none;">
                        <option>🇨🇳 中文</option>
                        <option>🇺🇸 English</option>
                        <option>🇯🇵 日本語</option>
                        <option>🇩🇪 Deutsch</option>
                    </select>
                    
                    <div class="cart-icon" id="cartIcon">
                        🛒
                        <div class="cart-count" id="cartCount">0</div>
                    </div>
                    
                    <!-- 登录按钮 -->
                    <button id="loginBtn" 
                        class="btn btn-outline" 
                        style="padding: 8px 16px; background: transparent; border: 2px solid white; color: white;" 
                        onclick="openLoginModal()">登录</button>

                    <!-- 个人中心按钮 -->
                    <button id="profileBtn" 
                        class="btn btn-outline" 
                        style="padding: 8px 16px; background: transparent; border: 2px solid white; color: white;" 
                        onclick="handleProfileClick()">个人中心</button>
                </div>
            </div>
        </div>
    </header>

    <!-- Hero Section -->
    <section class="hero">
        <div class="container">
            <div class="hero-content fade-in">
                <h1>华为Mate 70 Pro全球首发</h1>
                <p>突破想象，重新定义智慧体验</p>

                <div class="countdown" id="countdownContainer">
                    <div class="countdown-title" id="countdownTitle">距离全球发售还有</div>
                    <div class="countdown-timer" id="countdownTimer">
                        <div class="time-unit">
                            <span class="time-number" id="days">00</span>
                            <span class="time-label">天</span>
                        </div>
                        <div class="time-unit">
                            <span class="time-number" id="hours">00</span>
                            <span class="time-label">时</span>
                        </div>
                        <div class="time-unit">
                            <span class="time-number" id="minutes">00</span>
                            <span class="time-label">分</span>
                        </div>
                        <div class="time-unit">
                            <span class="time-number" id="seconds">00</span>
                            <span class="time-label">秒</span>
                        </div>
                    </div>
                </div>

                <button class="btn btn-primary pulse" id="heroButton" style="font-size: 18px; padding: 20px 40px;" onclick="window.location.href='product-detail.html'">
                    立即预约 🚀
                </button>
            </div>
        </div>
    </section>

    <!-- Product Showcase -->
    <section class="product-showcase" id="products">
        <div class="container">
            <h2 class="section-title fade-in">全球新品展示</h2>
            <div class="product-grid">
                
                <!-- Mate 70 Pro -->
                <div class="product-card fade-in" onclick="window.location.href='product-detail.html'">
                    <div class="product-image">
        <!-- 仅修改此处：删除⌚图标，替换为目标本地图片 -->
        <img src="/images/1.png" 
             alt="华为Mate 70 Pro产品图" 
             style="width: 100%; height: auto; object-fit: cover;">
        <!-- 注：style中width:100%确保图片适应容器，object-fit:cover避免图片拉伸变形，可按需调整 -->
    </div>
                    <div class="product-info">
                        <h3 class="product-title">华为Mate 70 Pro</h3>
                        <div class="product-price">¥6,999 / $999</div>
                        <p class="product-description">搭载全新麒麟9010芯片，支持卫星通话，50MP徕卡三摄，续航提升30%</p>
                        <div class="product-features">
                            <span class="feature-tag">5G</span>
                            <span class="feature-tag">卫星通话</span>
                            <span class="feature-tag">50MP三摄</span>
                            <span class="feature-tag">66W快充</span>
                        </div>
                        <div class="stock-status">
                            <div class="stock-indicator"></div>
                            <span>现货充足 - 全球同步发售</span>
                        </div>
                        <button class="btn btn-primary btn-full" onclick="event.stopPropagation(); openPurchaseModal('mate70-pro')">立即抢购</button>
                        <button class="btn btn-outline btn-full" style="margin-top: 10px;" onclick="event.stopPropagation(); addToCart('mate70-pro', '华为Mate 70 Pro', 6999)">加入购物车</button>
                    </div>
                </div>

                <!-- WATCH GT 5 -->
                <div class="product-card fade-in" onclick="window.location.href='product-detail.html'">
                    <div class="product-image">
        <!-- 仅修改此处：删除⌚图标，替换为目标本地图片 -->
        <img src="/images/2.png" 
             alt="华为WATCH GT 5产品图" 
             style="width: 100%; height: auto; object-fit: cover;">
        <!-- 注：style中width:100%确保图片适应容器，object-fit:cover避免图片拉伸变形，可按需调整 -->
    </div>
                    <div class="product-info">
                        <h3 class="product-title">华为WATCH GT 5</h3>
                        <div class="product-price">¥2,199 / $299</div>
                        <p class="product-description">专业运动健康监测，14天超长续航，支持eSIM独立通话</p>
                        <div class="product-features">
                            <span class="feature-tag">eSIM</span>
                            <span class="feature-tag">14天续航</span>
                            <span class="feature-tag">健康监测</span>
                            <span class="feature-tag">防水5ATM</span>
                        </div>
                        <div class="stock-status">
                            <div class="stock-indicator low"></div>
                            <span>库存紧张 - 仅剩231件</span>
                        </div>
                        <button class="btn btn-primary btn-full" onclick="event.stopPropagation(); openPurchaseModal('watch-gt5')">立即抢购</button>
                        <button class="btn btn-outline btn-full" style="margin-top: 10px;" onclick="event.stopPropagation(); addToCart('watch-gt5', '华为WATCH GT 5', 2199)">加入购物车</button>
                    </div>
                </div>

                <!-- FreeBuds Pro 4 -->
                <div class="product-card fade-in" onclick="window.location.href='product-detail.html'">
                    <div class="product-image">
        <!-- 仅修改此处：删除⌚图标，替换为目标本地图片 -->
        <img src="/images//3.png" 
             alt="华为FreeBuds Pro 4产品图" 
             style="width: 100%; height: auto; object-fit: cover;">
        <!-- 注：style中width:100%确保图片适应容器，object-fit:cover避免图片拉伸变形，可按需调整 -->
    </div>
                    <div class="product-info">
                        <h3 class="product-title">华为FreeBuds Pro 4</h3>
                        <div class="product-price">¥1,399 / $199</div>
                        <p class="product-description">智能降噪3.0，Hi-Res音质认证，多设备智能连接</p>
                        <div class="product-features">
                            <span class="feature-tag">智能降噪</span>
                            <span class="feature-tag">Hi-Res音质</span>
                            <span class="feature-tag">多设备连接</span>
                            <span class="feature-tag">36H续航</span>
                        </div>
                        <div class="stock-status">
                            <div class="stock-indicator"></div>
                            <span>现货充足 - 24小时发货</span>
                        </div>
                        <button class="btn btn-primary btn-full" onclick="event.stopPropagation(); openPurchaseModal('freebuds-pro4')">立即抢购</button>
                        <button class="btn btn-outline btn-full" style="margin-top: 10px;" onclick="event.stopPropagation(); addToCart('freebuds-pro4', '华为FreeBuds Pro 4', 1399)">加入购物车</button>
                    </div>
                </div>

            </div>
        </div>
    </section>

    <!-- Global Features -->
    <section class="global-features">
        <div class="container">
            <h2 class="section-title">全球化服务保障</h2>
            <div class="features-grid">
                <div class="feature-item fade-in">
                    <div class="feature-icon">🌍</div>
                    <h3 class="feature-title">全球同步发售</h3>
                    <p class="feature-description">200+国家和地区同步上市，本地化定价和服务</p>
                </div>
                <div class="feature-item fade-in">
                    <div class="feature-icon">⚡</div>
                    <h3 class="feature-title">极速配送</h3>
                    <p class="feature-description">全球物流网络，承诺48小时内发货，7天必达</p>
                </div>
                <div class="feature-item fade-in">
                    <div class="feature-icon">🔒</div>
                    <h3 class="feature-title">安全支付</h3>
                    <p class="feature-description">支持50+种支付方式，银行级安全加密保护</p>
                </div>
                <div class="feature-item fade-in">
                    <div class="feature-icon">🎧</div>
                    <h3 class="feature-title">24/7客服</h3>
                    <p class="feature-description">多语言客服团队，全天候在线支持和售后服务</p>
                </div>
            </div>
        </div>
    </section>

    <!-- Newsletter -->
    <section class="newsletter">
        <div class="container">
            <h2>订阅新品通知</h2>
            <p>第一时间获取华为新品发布信息和独家优惠</p>
            <form class="newsletter-form">
                <input type="email" class="newsletter-input" placeholder="输入您的邮箱地址">
                <button type="submit" class="btn btn-primary">立即订阅</button>
            </form>
        </div>
    </section>

    <!-- Footer -->
    <footer class="footer">
        <div class="container">
            <div class="footer-content">
                <div class="footer-section">
                    <h3>产品与服务</h3>
                    <ul>
                        <li><a href="#">手机</a></li>
                        <li><a href="#">平板</a></li>
                        <li><a href="#">笔记本</a></li>
                        <li><a href="#">穿戴设备</a></li>
                    </ul>
                </div>
                <div class="footer-section">
                    <h3>客户服务</h3>
                    <ul>
                        <li><a href="#">售后服务</a></li>
                        <li><a href="#">保修政策</a></li>
                        <li><a href="#">用户手册</a></li>
                        <li><a href="#">常见问题</a></li>
                    </ul>
                </div>
                <div class="footer-section">
                    <h3>关于华为</h3>
                    <ul>
                        <li><a href="#">公司简介</a></li>
                        <li><a href="#">新闻中心</a></li>
                        <li><a href="#">投资者关系</a></li>
                        <li><a href="#">可持续发展</a></li>
                    </ul>
                </div>
                <div class="footer-section">
                    <h3>全球站点</h3>
                    <ul>
                        <li><a href="#">🇨🇳 中国大陆</a></li>
                        <li><a href="#">🇺🇸 United States</a></li>
                        <li><a href="#">🇪🇺 Europe</a></li>
                        <li><a href="#">🇯🇵 日本</a></li>
                    </ul>
                </div>
            </div>
            <div class="footer-bottom">
                <p>&copy; 2024 华为技术有限公司 版权所有 | 隐私政策 | 使用条款 | 网站地图</p>
            </div>
        </div>
    </footer>

    <!-- Purchase Modal -->
    <div class="modal" id="purchaseModal">
        <div class="modal-content">
            <div class="queue-info">
                <h2>正在为您安排购买</h2>
                <div class="queue-position" id="queuePosition">12,847</div>
                <p>当前排队位置</p>
                
                <div class="queue-progress">
                    <div class="queue-progress-bar" id="progressBar" style="width: 25%"></div>
                </div>
                
                <p>预计等待时间：<strong id="waitTime">2分30秒</strong></p>
            </div>
            
            <div class="queue-entertainment">
                <h3>🎵 在等待的同时</h3>
                <p>观看华为Mate 70 Pro精彩视频</p>
                <div style="background: #000; height: 200px; border-radius: 10px; display: flex; align-items: center; justify-content: center; color: white; margin: 15px 0; overflow: hidden;">
    <video 
        controls 
        loop 
        autoplay 
        muted
        playsinline
        style="width: 100%; height: 100%; object-fit: cover;"
        poster="/images/5.mp4"
    >
        <source src="/images/5.mp4" type="video/mp4">
        您的浏览器不支持HTML5视频播放
    </video>
</div>

                <div style="margin-top: 20px;">
                    <div class="loading-spinner"></div>
                    <span style="margin-left: 10px;">系统正在为您处理...</span>
                </div>
            </div>
            
            <button class="btn btn-outline" onclick="closePurchaseModal()" style="margin-top: 20px;">
                取消排队
            </button>
        </div>
    </div>

    <script>
        // === 动态倒计时系统 ===
        class CountdownManager {
            constructor() {
                // 发布日期设置（可修改）
                this.launchDate = this.getLaunchDate();
                this.isCountdownEnded = false;
                this.previousValues = { days: null, hours: null, minutes: null, seconds: null };
                
                // DOM元素
                this.elements = {
                    days: document.getElementById('days'),
                    hours: document.getElementById('hours'),
                    minutes: document.getElementById('minutes'),
                    seconds: document.getElementById('seconds'),
                    title: document.getElementById('countdownTitle'),
                    container: document.getElementById('countdownContainer'),
                    timer: document.getElementById('countdownTimer'),
                    button: document.getElementById('heroButton')
                };
                
                this.startCountdown();
            }

            // 获取发布日期（当前时间+7天，可自定义）
            getLaunchDate() {
                const now = new Date();
                const launchDate = new Date(now.getTime() + 7 * 24 * 60 * 60 * 1000); // 7天后
                
                // 你也可以设置固定日期，例如：
                // const launchDate = new Date('2025-01-01 10:00:00');
                
                return launchDate;
            }

            // 更新倒计时显示
            updateCountdown() {
                const now = new Date().getTime();
                const distance = this.launchDate.getTime() - now;

                if (distance < 0) {
                    this.handleCountdownEnd();
                    return;
                }

                const days = Math.floor(distance / (1000 * 60 * 60 * 24));
                const hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
                const minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
                const seconds = Math.floor((distance % (1000 * 60)) / 1000);

                // 更新数字并添加动画效果
                this.updateNumberWithAnimation('days', days);
                this.updateNumberWithAnimation('hours', hours);
                this.updateNumberWithAnimation('minutes', minutes);
                this.updateNumberWithAnimation('seconds', seconds);
            }

            // 带动画效果更新数字
            updateNumberWithAnimation(unit, newValue) {
                const element = this.elements[unit];
                const formattedValue = newValue.toString().padStart(2, '0');
                
                if (this.previousValues[unit] !== newValue) {
                    // 添加动画类
                    element.classList.add('updating');
                    
                    // 更新数值
                    setTimeout(() => {
                        element.textContent = formattedValue;
                        this.previousValues[unit] = newValue;
                    }, 150);
                    
                    // 移除动画类
                    setTimeout(() => {
                        element.classList.remove('updating');
                    }, 300);
                }
            }

            // 处理倒计时结束
            handleCountdownEnd() {
                if (this.isCountdownEnded) return;
                
                this.isCountdownEnded = true;
                
                // 更新UI样式
                this.elements.container.classList.add('countdown-ended');
                this.elements.title.innerHTML = '🎉 全球发售现已开始！';
                this.elements.timer.innerHTML = '<div style="font-size: 24px; font-weight: bold;">立即抢购</div>';
                
                // 更新按钮
                this.elements.button.innerHTML = '🔥 立即抢购';
                this.elements.button.classList.remove('pulse');
                this.elements.button.style.background = 'linear-gradient(135deg, #10b981, #059669)';
                
                // 播放庆祝动画
                this.playCelebration();
                
                console.log('🎉 华为Mate 70 Pro全球发售开始！');
            }

            // 庆祝动画
            playCelebration() {
                // 创建彩带效果
                for (let i = 0; i < 50; i++) {
                    setTimeout(() => {
                        this.createConfetti();
                    }, i * 100);
                }
            }

            // 创建彩带粒子
            createConfetti() {
                const confetti = document.createElement('div');
                confetti.innerHTML = ['🎉', '🎊', '✨', '🌟'][Math.floor(Math.random() * 4)];
                confetti.style.cssText = `
                    position: fixed;
                    top: -50px;
                    left: ${Math.random() * 100}vw;
                    font-size: ${Math.random() * 20 + 20}px;
                    animation: confetti-fall ${Math.random() * 3 + 2}s linear forwards;
                    pointer-events: none;
                    z-index: 9999;
                `;
                
                document.body.appendChild(confetti);
                
                // 清理
                setTimeout(() => {
                    confetti.remove();
                }, 5000);
            }

            // 开始倒计时
            startCountdown() {
                // 立即更新一次
                this.updateCountdown();
                
                // 每秒更新
                this.countdownInterval = setInterval(() => {
                    this.updateCountdown();
                }, 1000);
            }

            // 重置倒计时（用于调试）
            resetCountdown(newDate) {
                if (newDate) {
                    this.launchDate = new Date(newDate);
                }
                this.isCountdownEnded = false;
                this.elements.container.classList.remove('countdown-ended');
                this.elements.title.innerHTML = '距离全球发售还有';
                
                clearInterval(this.countdownInterval);
                this.startCountdown();
            }

            // 销毁倒计时
            destroy() {
                clearInterval(this.countdownInterval);
            }
        }

        // 添加彩带下落动画CSS
        const confettiStyle = document.createElement('style');
        confettiStyle.innerHTML = `
            @keyframes confetti-fall {
                to {
                    transform: translateY(100vh) rotate(720deg);
                    opacity: 0;
                }
            }
        `;
        document.head.appendChild(confettiStyle);

        // === 其他页面功能 ===
        
        // 1. 全局DOM元素获取
        const $loginBtn = document.getElementById('loginBtn');
        const $profileBtn = document.getElementById('profileBtn');
        const $cartCount = document.getElementById('cartCount');
        const $cartIcon = document.getElementById('cartIcon');

        // 2. 模拟排队系统
        let queuePosition = 100;
        let progressWidth = 25;

        function openPurchaseModal(productId) {
            document.getElementById('purchaseModal').classList.add('active');
            startQueueSimulation();
        }

        function closePurchaseModal() {
            document.getElementById('purchaseModal').classList.remove('active');
        }

        function startQueueSimulation() {
            const interval = setInterval(() => {
                queuePosition -= Math.floor(Math.random() * 50) + 20;
                progressWidth += Math.random() * 3;
                
                if (queuePosition <= 0) {
                    queuePosition = 0;
                    progressWidth = 100;
                    clearInterval(interval);
                    
                    // 模拟抢购成功
                    setTimeout(() => {
                        alert('🎉 恭喜！抢购成功！\n\n订单号：HW20241214001\n请在30分钟内完成支付');
                        closePurchaseModal();
                        window.location.href = 'checkout.html';
                    }, 2000);
                }
                
                document.getElementById('queuePosition').textContent = queuePosition.toLocaleString();
                document.getElementById('progressBar').style.width = Math.min(progressWidth, 100) + '%';
                
                const waitMinutes = Math.floor(queuePosition / 100);
                const waitSeconds = queuePosition % 60;
                document.getElementById('waitTime').textContent = `${waitMinutes}分${waitSeconds}秒`;
            }, 1000);
        }

        // 3. 滚动动画
        function isInViewport(element) {
            const rect = element.getBoundingClientRect();
            return (
                rect.top >= 0 &&
                rect.left >= 0 &&
                rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) &&
                rect.right <= (window.innerWidth || document.documentElement.clientWidth)
            );
        }

        function handleScrollAnimations() {
            const elements = document.querySelectorAll('.fade-in');
            elements.forEach(element => {
                if (isInViewport(element)) {
                    element.style.animation = 'fadeIn 0.6s ease-in-out forwards';
                }
            });
        }
        window.addEventListener('scroll', handleScrollAnimations);
        window.addEventListener('load', handleScrollAnimations);

        // 4. 自动清缓存（24小时）
        function autoClearCache() {
            const now = Date.now();
            const cacheExpire = 24 * 60 * 60 * 1000;
            const lastClear = parseInt(localStorage.getItem('lastClear')) || 0;

            if (now - lastClear > cacheExpire) {
                console.log('🧹 自动清缓存：超过24小时，清理本地存储数据');
                localStorage.removeItem('cartItems');
                localStorage.removeItem('cartData');
                localStorage.removeItem('isLoggedIn');
                localStorage.setItem('lastClear', now);
                $cartCount.textContent = 0;
                updateLoginState();
            }
        }
        window.addEventListener('load', autoClearCache);
        setInterval(autoClearCache, 60 * 60 * 1000);

        // 5. 登录/退出逻辑
        function updateLoginState() {
            const isLoggedIn = localStorage.getItem('isLoggedIn') === 'true';

            if (!isLoggedIn) {
                $loginBtn.disabled = false;
                $loginBtn.classList.remove('disabled-btn');
                $loginBtn.textContent = '登录';
                $loginBtn.style.background = 'transparent';
                $loginBtn.style.border = '2px solid white';
                $loginBtn.style.color = 'white';

                $profileBtn.disabled = true;
                $profileBtn.classList.add('disabled-btn');
                $profileBtn.textContent = '个人中心';
                $profileBtn.style.background = '#ccc';
                $profileBtn.style.border = '2px solid #d1d5db';
                $profileBtn.style.color = '#666';

                localStorage.removeItem('cartItems');
                localStorage.removeItem('cartData');
                $cartCount.textContent = 0;
            } else {
                $loginBtn.disabled = true;
                $loginBtn.classList.add('disabled-btn');
                $loginBtn.textContent = '已登录';
                $loginBtn.style.background = '#ccc';
                $loginBtn.style.border = '2px solid #d1d5db';
                $loginBtn.style.color = '#666';

                $profileBtn.disabled = false;
                $profileBtn.classList.remove('disabled-btn');
                $profileBtn.textContent = '个人中心';
                $profileBtn.style.background = 'transparent';
                $profileBtn.style.border = '2px solid white';
                $profileBtn.style.color = 'white';
            }
        }

        function login() {
            localStorage.setItem('isLoggedIn', 'true');
            updateLoginState();
            alert('登录成功！现在可以使用购物车和个人中心。');
            window.location.href = 'index.html';
        }

        function logout() {
            localStorage.removeItem('isLoggedIn');
            updateLoginState();
            alert('已退出登录，购物车和个人中心不可用。');
        }

        // 6. 购物车控制
        function handleCartClick() {
            const isLoggedIn = localStorage.getItem('isLoggedIn') === 'true';
            if (!isLoggedIn) {
                alert('请先登录才能使用购物车');
                window.location.href = 'login.html';
                return;
            }
            window.location.href = 'cart.html';
        }

        function addToCart(productId, productName, productPrice) {
            const isLoggedIn = localStorage.getItem('isLoggedIn') === 'true';
            if (!isLoggedIn) {
                alert('请先登录才能添加商品到购物车');
                window.location.href = 'login.html';
                return;
            }

            let cartData = JSON.parse(localStorage.getItem('cartData')) || [];
            let cartItems = parseInt(localStorage.getItem('cartItems')) || 0;

            const existingItemIndex = cartData.findIndex(item => item.id === productId);
            if (existingItemIndex > -1) {
                cartData[existingItemIndex].quantity += 1;
            } else {
                cartData.push({
                    id: productId,
                    name: productName,
                    price: productPrice,
                    quantity: 1,
                    addedTime: new Date().getTime()
                });
            }

            cartItems = cartData.reduce((total, item) => total + item.quantity, 0);
            localStorage.setItem('cartData', JSON.stringify(cartData));
            localStorage.setItem('cartItems', cartItems);

            $cartCount.textContent = cartItems;
            alert(`✅ ${productName} 已加入购物车！\n当前购物车共 ${cartItems} 件商品`);
        }

        // 7. 个人中心控制
        function handleProfileClick() {
            const isLoggedIn = localStorage.getItem('isLoggedIn') === 'true';
            if (!isLoggedIn) {
                alert('请先登录才能进入个人中心');
                window.location.href = 'login.html';
                return;
            }
            window.location.href = 'user-center.html';
        }

        // 8. 登录模态框
        function openLoginModal() {
            window.location.href = 'login.html';
        }

        // 9. 邮件订阅
        document.querySelector('.newsletter-form').addEventListener('submit', function(e) {
            e.preventDefault();
            const email = e.target.querySelector('input').value;
            if (email) {
                alert('感谢订阅！您将第一时间收到华为新品发布信息。');
                e.target.querySelector('input').value = '';
            }
        });

        // 10. 页面加载初始化
        let countdownManager;

        window.addEventListener('load', function() {
            // 初始化倒计时
            countdownManager = new CountdownManager();
            
            // 初始化登录/个人中心按钮状态
            updateLoginState();

            // 初始化购物车数量
            const cartItems = parseInt(localStorage.getItem('cartItems')) || 0;
            $cartCount.textContent = cartItems;

            // 绑定购物车点击事件
            $cartIcon.addEventListener('click', handleCartClick);

            console.log('🚀 华为全球新品订购网站首页加载完成');
            console.log(`⏰ 倒计时目标时间：${countdownManager.launchDate.toLocaleString()}`);
        });

        // === 调试功能（控制台使用） ===
        // 在浏览器控制台输入以下命令进行调试：

        // 重置倒计时到30秒后结束（测试倒计时结束效果）
        window.debugSetCountdown30s = () => {
            const testDate = new Date(Date.now() + 30000); // 30秒后
            countdownManager.resetCountdown(testDate);
            console.log('⏰ 倒计时已设置为30秒后结束');
        };

        // 重置倒计时到3天后结束
        window.debugSetCountdown3d = () => {
            const testDate = new Date(Date.now() + 3 * 24 * 60 * 60 * 1000); // 3天后
            countdownManager.resetCountdown(testDate);
            console.log('⏰ 倒计时已设置为3天后结束');
        };

        // 立即结束倒计时（测试结束效果）
        window.debugEndCountdown = () => {
            const testDate = new Date(Date.now() - 1000); // 1秒前（已过期）
            countdownManager.resetCountdown(testDate);
            console.log('⏰ 倒计时已立即结束');
        };

        // 模拟登录
        window.debugLogin = () => {
            login();
            console.log('👤 已模拟登录');
        };

        // 模拟退出
        window.debugLogout = () => {
            logout();
            console.log('👤 已模拟退出');
        };
    </script>
</body>
</html>